var test = 0

$(function () {
  $('#customephone').blur(function () {
    var phone = /^1(3\d|4[5-8]|5[0-35-9]|6[567]|7[01345-8]|8\d|9[025-9])\d{8}$/
    if ($(this).val() == '') {
      $('#customephoneId').removeClass('ok_prompt')
      $('#customephoneId').addClass('error_prompt').html('手机号不能为空!')
    } else if (phone.test($(this).val())) {
      $('#customephoneId').removeClass('error_prompt')
      $('#customephoneId').addClass('ok_prompt').html('手机号正确!')
    } else {
      $('#customephoneId').removeClass('ok_prompt')
      $('#customephoneId').addClass('error_prompt').html('请输入合法手机号!')
    }
  })

  $('#menubtn').click(function(){
    $("#navBar").css({
      backgroundColor:"white",
    })
  })
})

function mHttp() {
  var b_time = $('#b_time').val()
  var client_name = $('#client_name').val()
  var client_phone = $('#client_phone').val()
  var client_brand = $('#client_brand').val()
  var v_client = $('#v_client').val()
  var ding_client = $('#ding_client').val()
  var url =  host + '/business?b_time=' + b_time+ '&client_name=' + client_name + '&client_phone=' + client_phone + '&client_brand=' + client_brand + '&v_client=' + v_client  + '&ding_client=' + ding_client
  let httpRequest = new XMLHttpRequest();//第一步：创建需要的对象
  httpRequest.open('POST', url, true); //第二步：打开连接/***发送json格式文件必须设置请求头 ；如下 - */
  // httpRequest.open('GET', url, true); //第二步：打开连接/***发送json格式文件必须设置请求头 ；如下 - */
  httpRequest.setRequestHeader("Access-Control-Allow-Credentials", true);//设置请求头 注：post方式必须设置请求头（在建立连接后设置请求头）var obj = { name: 'zhansgan', age: 18 };
  httpRequest.setRequestHeader("Access-Control-Allow-Origin", "*");
  httpRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;");
  var data = 'b_time=' + b_time+ '&client_name=' + client_name + '&client_phone=' + client_phone + '&client_brand=' + client_brand + '&v_client=' + v_client  + '&ding_client=' + ding_client
  httpRequest.send(data);//发送请求 将json写入send中
  /**
   * 获取数据后的处理程序
   */
  httpRequest.onreadystatechange = function () {//请求后的回调接口，可将请求成功后要执行的程序写在其中
      if (httpRequest.readyState == 4 && httpRequest.status == 200) {//验证请求是否发送成功
          var json = JSON.parse(httpRequest.responseText);//获取到服务端返回的数据
          console.log(json);
          if(json['message'] == '提交成功'){
            alert('提交成功！')
          }else{
            alert('提交失败！')
          }
      }
  };
}